# $Id: PKGBUILD 89662 2013-05-02 05:25:47Z foutrelis $
# Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
# Contributor: Malte Rabenseifner <malte@zearan.de>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: FUBAR <mrfubar@gmail.com>

pkgname=('shorewall' 'shorewall6' 'shorewall-core')
pkgver=4.5.16.1
pkgrel=1
arch=('any')
url="http://www.shorewall.net/"
license=('GPL')
source=(http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.16/$pkgname-$pkgver.tar.bz2
        http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.16/shorewall6-$pkgver.tar.bz2
        http://www.shorewall.net/pub/$pkgname/4.5/$pkgname-4.5.16/shorewall-core-$pkgver.tar.bz2)
sha256sums=('d0f24aefcb26f761943c62b2dff9d1f1368f46d588a1495e85558c364a157b9d'
            'df6a5bb5568ae76f278f8a9bb6dd303f48d2f126a257bfbed6de91dcb5122552'
            '7c419ac11a89791f29e3eaf0cd5c1a8dc455cd2e05942d00046b0ea94c2de147')

build() {
  for product in shorewall{,6,-core}; do
    pushd "$srcdir/$product-$pkgver"
    ./configure
    popd
  done
}

package_shorewall() {
  pkgdesc="An iptables-based firewall for Linux systems"
  depends=('shorewall-core' 'perl')
  backup=(etc/shorewall/{accounting,actions,blrules,clear,conntrack,ecn,findgw,hosts,init,initdone,interfaces,lib.private,maclist,masq,nat,netmap,params,policy,providers,proxyarp,refresh,refreshed,restored,routes,stoppedrules,rtrules,rules,scfilter,secmarks,shorewall.conf,start,started,stop,stopped,tcclasses,tcclear,tcdevices,tcfilters,tcinterfaces,tcpri,tcrules,tos,tunnels,zones})

  cd "$srcdir/$pkgname-$pkgver"

  do_install
}

package_shorewall6() {
  pkgdesc="An iptables-based firewall for Linux systems (with IPv6 support)"
  depends=('shorewall')
  backup=(etc/shorewall6/{accounting,actions,blrules,clear,conntrack,hosts,init,interfaces,maclist,masq,netmap,params,policy,providers,proxyndp,refresh,refreshed,restored,routes,stoppedrules,rtrules,rules,scfilter,secmarks,shorewall6.conf,start,started,stop,stopped,tcclasses,tcclear,tcdevices,tcfilters,tcinterfaces,tcpri,tcrules,tos,tunnels,zones})

  cd "$srcdir/$pkgname-$pkgver"

  do_install 6
}

package_shorewall-core() {
  pkgdesc="Core Shorewall libraries"
  depends=('iptables' 'iproute2')

  cd "$srcdir/$pkgname-$pkgver"

  DESTDIR="$pkgdir" ./install.sh
}

do_install() {
  local _name_suffix=$1

  sed -i -e 's|^MODULE_SUFFIX=ko$|&.gz|' \
         -e 's|/subsys||' \
      "configfiles/shorewall$_name_suffix.conf"

  DESTDIR="$pkgdir" ./install.sh

  install -d "$pkgdir/usr/share/doc/shorewall$_name_suffix/"
  cp -r Samples$_name_suffix "$pkgdir/usr/share/doc/shorewall$_name_suffix/"

  chmod -R 644 "$pkgdir/etc/shorewall$_name_suffix/"
  chmod 755 "$pkgdir/etc/shorewall$_name_suffix/"
  chmod 644 "$pkgdir/usr/share/shorewall$_name_suffix/modules"
  chmod 644 "$pkgdir/usr/share/shorewall$_name_suffix/helpers"

  # Fix systemd service file permissions
  chmod 644 "$pkgdir/usr/lib/systemd/system/shorewall$_name_suffix.service"
}

# vim:set ts=2 sw=2 et:
